<template>
  <a-modal
    title="列表"
    :width="500"
    :visible="visible"
    :confirmLoading="loading"
    :destroyOnClose="true"
    @cancel="
      () => {
        $emit('cancel')
      }
    "
    :footer="null"
  >
    <a-spin :spinning="loading">
      <a-table
        ref="table"
        size="default"
        rowKey="sendid"
        :columns="columns"
        :dataSource="list.list"
        :pagination="parameter"
      >
        <span slot="delivrdAt" slot-scope="text">
          {{text | timeToStr}}
        </span>
      </a-table>
    </a-spin>
  </a-modal>
</template>

<script>
import pick from 'lodash.pick'
import { STable } from '@/components'
import { smsCallbackLogList } from '@/api/sms'
// 表单字段
const columns = [
  {
    title: '手机号码',
    dataIndex: 'mobile',
  },
  {
    title: '回执时间',
    dataIndex: 'delivrdAt',
    // customRender: (text)=>text ? '':''
    scopedSlots: {customRender: 'delivrdAt'}
  },
  {
    title: '结果',
    dataIndex: 'status',
    customRender: (text)=>text == 'DELIVRD'? '成功':'失败'
  },
]

export default {
  name: 'MSG-list',
  props: {
    visible: {
      type: Boolean,
      required: true,
    },
    data: {
      type: Object,
      required: {},
    },
  },
  components: {
    STable,
  },
  data() {
    this.columns = columns
    return {
      form: this.$form.createForm(this),
      list: {
        list: [],
        total: 0,
      },
      loading: false,
      // statusMap:{
      //   1:{status: 'green', name: '通过'},
      //   2:{status: 'red', name: '驳回'}
      // },
      // typeMap:{
      //   1:{status: 'green', name: '初审'},
      //   2:{status: 'red', name: '终审'},
      //   3:{status: 'blue', name: '打款'},
      // },
      parameter: {
        pageNum: 1,
        pageSize: 5,
        showTotal: (t) => `共 ${t} 条数据`,
      },
      init: true,
    }
  },
  created() {},
  methods: {
    getList() {
      this.loading = true
      let data = this.data
      let parameter = this.parameter

      let rData = {
        msgId: data.id,
        pageNum: parameter.pageNum,
        pageSize: parameter.pageSize,
      }
      smsCallbackLogList(rData).then((res) => {
        if(res.data && res.data.jsonData)
        this.list.list = JSON.parse(res.data.jsonData)
        
      }).finally(()=>{
        this.loading = false
      })
    },
  },
  watch: {
    visible: function (n, o) {
      if (n) {
        this.getList()
      }else{
        this.parameter.pageNum = 1
      }
    },
  },
}
</script>
<style lang="less" scoped>
.jumpName {
  cursor: pointer;
}
</style>